var aimgList = [];
//    获取图片链接数组
var imgscroll = document.getElementById("imgList").children;
for (var m = 0; m < imgscroll.length; m++) {
    aimgList[m] = imgscroll[m].getAttribute("src");
//        给每个图片添加点击事件
    imgscroll[m].addEventListener('click', function () {
//        获取所点击图片的index
        var index = this.getAttribute("data-index");
        var box = document.createElement('div');
        box.className = "model-box";
//            点击图片模态框消失
        box.addEventListener('click', function (e) {
            box.parentNode.removeChild(box);
        });
//        模态框图片动态添加
        var strDOM = "", strDOM2 = "";
        strDOM += '<div class="swiper-container swiper-container-horizontal">';
        strDOM += '<div class="swiper-wrapper" style="transition-duration: 0ms; transform: translate3d(0, 0px, 0px);">';
        for (var i = 0; i < aimgList.length; i++) {
            strDOM += '<div class="swiper-slide" style="width: 500px;">';
            strDOM += '<img class="swiper-slide-img" src="' + aimgList[i] + '">';
            strDOM += '</div>';
        }
        strDOM += '</div>';
        strDOM += '</div>';
//        分页动态添加
        strDOM2 += '<div class="swiper-pagination swiper-pagination-clickable swiper-pagination-bullets">';
        for (var j = 0; j < aimgList.length; j++) {
            strDOM2 += '<span class="swiper-pagination-bullet"></span>'
        }
        strDOM2 += '</div>';
//            页面中加入元素
        box.innerHTML = strDOM + strDOM2;
        document.body.appendChild(box);
//            渲染
        var swiper = new Swiper('.swiper-container', {
            initialSlide: index,
            pagination: '.swiper-pagination',
            paginationClickable: true
        });
    });
}